/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package mobiqueen.googlemaps;

import android.app.AlertDialog;
import android.content.Context;
import android.graphics.drawable.Drawable;
import com.google.android.maps.ItemizedOverlay;
import com.google.android.maps.OverlayItem;
import java.util.ArrayList;

/**
 *
 * @author jv
 */
public class GoogleMapItems extends ItemizedOverlay{

    private ArrayList<OverlayItem> mOverlays = new ArrayList<OverlayItem>();
    private Context mContext;
    
    public GoogleMapItems(Drawable defaultMarker)
    {
        super(boundCenterBottom(defaultMarker));
    }

    public GoogleMapItems(Drawable defaultMarker, Context context)
    {
        super(defaultMarker);
        mContext = context;
    }

    public void addOverlay(OverlayItem overlay) {
        mOverlays.add(overlay);
        populate();
    }

    @Override
    protected boolean onTap(int index) 
    {  
        OverlayItem item = mOverlays.get(index);  
        AlertDialog.Builder dialog = new AlertDialog.Builder(mContext);  
        dialog.setTitle(item.getTitle());  
        dialog.setMessage(item.getSnippet());  
        dialog.show();  
        return true;
    }

    @Override
    protected OverlayItem createItem(int i) {
        return mOverlays.get(i);
    }

    @Override
    public int size() {
        return mOverlays.size();
    }
}
